/**
 *
 */
package com.yangtao.prototype.common.select.web;

import com.yangtao.framework.common.Option;
import com.yangtao.framework.dojo.DojoDataModel;
import com.yangtao.framework.util.Struts2Utils;
import com.yangtao.framework.web.struts2.BaseAction;
import com.yangtao.prototype.common.select.service.SelectService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 杨涛
 */
public class SelectAction extends BaseAction<SelectModel, SelectService> {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	public void linkSelect() {
		List<Option> slaveOptions = service.getSlaveList(request.getParameter("code"), request.getParameter("type"));
		Struts2Utils.renderJson(slaveOptions);
	}

	public void obtainStore() {
		String searchAttr = request.getParameter("searchAttr");
		String attrVal = request.getParameter(searchAttr);
		List<Object> store = service.getStoreByUser(model.getUserId(), model.getStoreType(), searchAttr, attrVal);
//        List<Object> store = new ArrayList<Object>();
//	    Customer c1 = new Customer();
//	    c1.setCode("cust1");
//	    c1.setName("客户1");
//	    c1.setId("id1");
//	    store.add(c1);
//
//	    Customer c2 = new Customer();
//	    c2.setCode("abc");
//	    c2.setName("客户2");
//	    c2.setId("id2");
//	    store.add(c2);
//
		DojoDataModel ddm = new DojoDataModel();
		ddm.setItems(store);
		renderJson(ddm);
	}

	private Map<String, Object> buildParam() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("user", model.getUserName());
		param.putAll(request.getParameterMap());
		return param;
	}
}
